package com.mask.share.life.jk;

import cn.hutool.core.io.FileUtil;
import com.google.common.collect.Lists;
import com.mask.share.life.jk.hander.Before1ImageHandler;
import com.mask.share.life.jk.hander.Before50ImageHandler;
import com.mask.share.life.jk.hander.ImageHandler;
import com.mask.share.life.jk.hander.handler_result.ImageHandlerResult;
import com.mask.share.life.jk.hander.handler_result.MergeHandlerResult;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

@Slf4j
public class Main {

    public static void main(String[] args) {
        /** 先清空一下结果 */
        String resultDir = "D:\\temp";
        File folder = new File(resultDir);
        if (folder.exists() && folder.isDirectory()) {
            FileUtil.del(folder);
            FileUtil.mkdir(resultDir);
        } else {
            System.out.println("文件夹不存在或者不是一个目录");
        }

        long start = System.currentTimeMillis();


        /** 构建处理对象*/
        int bufferSize = 50;
        List<String> sourceVideos = Lists.newArrayList(
                "D:\\jk\\7c248a09e9cd465f4a6c66f13b86b632.mp4"
        );
        ArrayList<ImageHandler> handlers = Lists.newArrayList(new Before1ImageHandler(), new Before50ImageHandler());
        ImageHandlerResult imageHandlerResult = new MergeHandlerResult(resultDir);


        VideoWorker worker = new VideoWorker.Builder(
                sourceVideos,
                handlers,
                imageHandlerResult)
                // 根据实际的碰撞位置，设置截图位置
                .needCatImage(414, 253, 436, 277)
                .bufferSize(bufferSize)
                .setThreadCore(5)
                .build();


        /** 执行操作*/
        worker.doWork();

        /** 最后用你充满智慧的眼睛，去看 $resultDir 下的图片，判断一下*/

        System.out.println("总耗时:" + (System.currentTimeMillis() - start));
    }
}

